package me.shingohu.man.intergation;

import android.app.Application;

import com.squareup.leakcanary.LeakCanary;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import me.shingohu.man.BuildConfig;

/**
 * Created by hujie on 17/4/15.
 */

public class LeakcanaryManager {

    private static boolean userLeakcanary() {
        return BuildConfig.LEAKCANARY_OPEN;
    }

    public static void initLeakcanary(Application application) {
        if (userLeakcanary()) {
            Observable.timer(300, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.newThread()).subscribe(new Consumer<Long>() {
                @Override
                public void accept(@NonNull Long aLong) throws Exception {
                    LeakCanary.install(application);
                }
            });
        }
    }
}
